package gameTheory;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import model.Route;

public class Strategy {
	private Map<Route,Double> probs;
	
	public Strategy(Map<Route,Double> probs){
		this.probs = probs;
		check();
	}
	
	public Set<Route> getRoutes(){
		return probs.keySet();
	}
	
	public Double getProbability(Route r){
		return probs.get(r);
	}
	
	public void check(){
		double sum = 0;
		Collection<Double> probValues = probs.values();
		for (Double d : probValues) {
			sum += d;
		}
		assert Math.abs(sum-1)<0.01 : "Sum of all probabilitys should be one"+sum;
	}
	
	public boolean isMixed(){
		for(Double d:probs.values()){
			if(d==1)
				return false;
		}
		return true;
	}
	
	public String toString(){
		if(isMixed())
			return probs.toString();
		else{
			String s="";
			for(Route r:probs.keySet()){
				if(probs.get(r)==1)
					s=r.toString();
			}
			return s;
		}
	}
	
}
